<!--
 * @Author: fanyaqing
 * @Date: 2021-08-06 08:05:40
 * @LastEditTime: 2021-08-23 08:25:12
 * @LastEditors: fanyaqing
 * @Description: 
 * @FilePath: \supermall\src\components\content\goods\GoodsListItem.vue
-->
<template>
  <div class="goods-item" @click="itemClick">
    <img v-lazy="goodsItem.show.img" @load="imageLoad">
    <div class="goods-info">
      <p>{{goodsItem.title}}</p>
      <span class="price">{{goodsItem.price}}</span>
      <span class="collect">{{goodsItem.cfav}}</span>
    </div>
  </div>
</template>
<script>
export default {
  props:{
    goodsItem:{
      type:Object,
      default:()=>{
        return {};
      }
    }
  },
  data() {
    return {
      
    }
  },
  methods:{
    imageLoad(){
      // 事件总线
      this.$bus.$emit('imageLoaded')
    },
    itemClick(){
      this.$router.push('/detail/'+this.goodsItem.id)
    }
  }
}
</script>
<style scoped>
  .goods-item{
    width: 48%;
    /* position: relative; */
    /* padding-bottom: 40px; */
  }
  .goods-item img{
    width: 100%;
    border-radius: 5px;
  }
  .goods-info{
    /* position: absolute;
    bottom: 5px;
    left: 0;
    right: 0; */
    text-align: center;
    font-size: 12px;
    /* overflow: hidden; */

  }
  .goods-info p{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
  }
  .goods-info .price{
    color: var(--color-high-text);
    margin-right: 20px;
  }
  .goods-info .collect {
    position: relative;
  }
  .goods-info .collect::before{
    /* 在某个元素前出现，使用before等属性，必须要子元素绝对定位，父元素相对定位 */
    content: '';
    position: absolute;
    left: -15px;
    top: -1px;
    width: 14px;
    height: 14px;
    background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
  }

</style>